export class StringUtil {
    static combindQuery(...args): string {
        let str: string = ""
        if (args) {
            for (let i: number = 0; i < args.length; i++) {
                str += args[0] + "#";
            }
        }

        return str;
    }


    static getStringInex(ss: Array<string>, tt): number {
        for (let i: number = 0; i < ss.length; i++) {
            if (ss[i] === tt) {
                return i;
            }
        }

        return 0;
    }


    /** 将(100, 200),(100,200)之类的字符解析成数组*/
    static formStringToArray(t: string, insert: number = null): Array<number> {
        //合法性验证
        let r: Array<number> = [];
        let reg = /\(\d+s*,s*\d+\)/g;
        let reg1 = /\d+/g;
        let rs = (t ?? '').match(reg);
        if (rs) {
            for (let i of rs) {
                // i.replace("(", "");
                // i.replace(")", "");
                let is = i.match(reg1);
                r.push(+is[0] ?? 0);
                r.push(+is[1] ?? 0);
                insert && r.push(insert);
            }
        }

        return r;
    }

    
    static FormatArrayToPosString(a: Array<number>, x: Array<number>): string {
        let str = "";

        if (a) {
            let end = a.length - 1;
            for (let [i, xx] of x.entries()) {
                for (let [index, y] of a.entries()) {
                    str += this.formatTo(xx, y);

                    if (index < end) {
                        str += ",";
                    }
                }

                if (i < x.length - 1) {
                    str += ",";
                }
            }

        }

        return str;
    }

    static formatTo(x, y): string {
        return "(" + x + "," + y + ")";
    }


    /**
     * 
     * @param arr 
     * @param splitNum 需要对组内的多少个数据统计
     * @param itemSize 每组多少个数据
     * @returns 
     */
    static formatArrayToString(arr: Array<any>, splitNum: number = 1, itemSize: number = 1): string{
        if(!arr ){ return ''}

        let res: Array<string> = [];

        let format = (fs: Array<number>)=>{
            return '(' + fs.join(",") + ')';
        }

        for(let i: number = 0; i < arr.length; i+= itemSize){

            let j: number = i;
            let fs: Array<number> = [];
            while(j < i+splitNum){
                fs.push(arr[j]);
                j++;
            }

            res.push(format(fs));  
        }

        return res.join(",");
    }


    /** */
}